package cn.csc.module.pay.service.funddetailsinfo;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.math.BigInteger;
import java.util.*;
import cn.csc.module.pay.controller.admin.funddetailsinfo.vo.*;
import cn.csc.module.pay.dal.dataobject.funddetailsinfo.PayFundDetailsInfoDO;
import cn.csc.framework.common.pojo.PageResult;

import cn.csc.module.pay.convert.funddetailsinfo.PayFundDetailsInfoConvert;
import cn.csc.module.pay.dal.mysql.funddetailsinfo.PayFundDetailsInfoMapper;

import static cn.csc.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.csc.module.pay.enums.ErrorCodeConstants.*;

/**
 * 用户资金提现分账明细 Service 实现类
 *
 * @author 华南城
 */
@Service
@Validated
public class PayFundDetailsInfoServiceImpl implements PayFundDetailsInfoService {

    @Resource
    private PayFundDetailsInfoMapper fundDetailsInfoMapper;

    @Override
    public BigInteger createFundDetailsInfo(PayFundDetailsInfoCreateReqVO createReqVO) {
        // 插入
        PayFundDetailsInfoDO fundDetailsInfo = PayFundDetailsInfoConvert.INSTANCE.convert(createReqVO);
        fundDetailsInfoMapper.insert(fundDetailsInfo);
        // 返回
        return fundDetailsInfo.getId();
    }

    @Override
    public void updateFundDetailsInfo(PayFundDetailsInfoUpdateReqVO updateReqVO) {
        // 校验存在
        validateFundDetailsInfoExists(updateReqVO.getId());
        // 更新
        PayFundDetailsInfoDO updateObj = PayFundDetailsInfoConvert.INSTANCE.convert(updateReqVO);
        fundDetailsInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteFundDetailsInfo(BigInteger id) {
        // 校验存在
        validateFundDetailsInfoExists(id);
        // 删除
        fundDetailsInfoMapper.deleteById(id);
    }

    private void validateFundDetailsInfoExists(BigInteger id) {
        if (fundDetailsInfoMapper.selectById(id) == null) {
            throw exception(FUND_DETAILS_INFO_NOT_EXISTS);
        }
    }

    @Override
    public PayFundDetailsInfoDO getFundDetailsInfo(BigInteger id) {
        return fundDetailsInfoMapper.selectById(id);
    }

    @Override
    public List<PayFundDetailsInfoDO> getFundDetailsInfoList(Collection<BigInteger> ids) {
        return fundDetailsInfoMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<PayFundDetailsInfoDO> getFundDetailsInfoPage(PayFundDetailsInfoPageReqVO pageReqVO) {
        return fundDetailsInfoMapper.selectPage(pageReqVO);
    }

    @Override
    public List<PayFundDetailsInfoDO> getFundDetailsInfoList(PayFundDetailsInfoExportReqVO exportReqVO) {
        return fundDetailsInfoMapper.selectList(exportReqVO);
    }

}
